﻿using System.Collections;

namespace SPSiteColumnUsage
{
    /// <summary>
    /// Helper class for extension methods on ICollection
    /// </summary>
    public static class ICollectionMethodes
    {
        /// <summary>
        /// Copies the collection to array of a particular type and validate for null at the same time
        /// </summary>
        /// <typeparam name="T">Object type in the array</typeparam>
        /// <param name="collection">The collection.</param>
        /// <returns>Returns an array of the specified type.</returns>
        public static T[] CopyToArray<T>(this ICollection collection)
        {
            if (collection == null) { return new T[0]; }

            T[] array = new T[collection.Count];
            collection.CopyTo(array, 0);

            return array;
        }
    }
}
